<template>
  <div class="app-container">
    <el-form :inline="true" :model="pageInfo" class="demo-form-inline">
      <el-form-item label="用户名">
        <el-input v-model="pageInfo.username" placeholder="用户名" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="toAdd">新增</el-button>
        <el-button type="primary" @click="del">删除</el-button>
      </el-form-item>

    </el-form>

    <template>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >

        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column
          type="index"
          label="Id"
          width="180"
        />
        <el-table-column
          prop="username"
          label="用户名"
          width="180"
        />
        <el-table-column
          prop="operation"
          label="用户操作"
          width="180"
        />
        <el-table-column
          prop="method"
          label="请求方法"
          width="180"
        />
        <el-table-column
          prop="params"
          label="请求参数"
          width="180"
        />
        <el-table-column
          prop="time"
          label="执行时长（毫秒）"
          width="180"
        />
        <el-table-column
          prop="ip"
          label="IP地址"
          width="180"
        />
        <el-table-column
          prop="createDate"
          label="创建时间"
          width="180"
        />

      </el-table>
    </template>
    <el-pagination
      :current-page="pageInfo.pageNum"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />

  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [],
      total: null,
      pageInfo: {
        pageNum: null,
        pageSize: null,
        username: null,
        mobile: null,
        deptName: null
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.axios.post('http://localhost:8091/log/list', this.pageInfo).then((response) => {
        this.tableData = response.data.obj.list
        this.pageInfo.pageNum = response.data.obj.pageNum
        this.pageInfo.pageSize = response.data.obj.pageSize
        this.total = response.data.obj.total
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageInfo.pageSize = val
      this.init()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageInfo.pageNum = val
      this.init()
    },
    onSubmit() {
      this.init()
    },
    toAdd() {

    },
    del() {

    }
  }
}
</script>

